package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2023-03-15
 * Time: 18:30
 */
//继承Thread类,重写run方法
class MyThread extends Thread{
    @Override
    public void run() {
        System.out.println("hello t ");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {//sleep代表正在睡着,,就被唤醒了
            throw new RuntimeException(e);
        }
    }
}
public class ThreadDemo1 {
    public static void main(String[] args)  {
        Thread t = new MyThread();//向上转型
        //创建一个新的线程
        t.start();
        t.run();//注意,这个方法代表还是主线程里面的
        while (true) {

            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
